.ig
The MIT License (MIT)

Copyright (c) 2019 Jinzhou Zhang
Copyright (c) 2017 Junegunn Choi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
..
.TH sk 1 "Oct 2018" "sk 0.17.5" "sk - a command-line fuzzy finder"

.SH NAME
sk - fuzzy finder in rust

.SH SYNOPSIS
sk [options]

.SH DESCRIPTION
sk is a general-purpose command-line fuzzy finder.

.SH OPTIONS
.SS Search mode
.TP
.B "-e, --exact"
Enable exact-match
.TP
.B "--regex"
Search with regular expression instead of fuzzy match
.TP
.BI "--algo=" TYPE
Fuzzy matching algorithm (default: skim_v2)

.br
.BR skim_v2 " Almost always the one to choose
.br
.BR skim_v1 " The legacy algorithm
.br
.BR clangd "  the one used by clangd for keyword completion
.br

.TP
.BI "--case=" "[smart,respect,ignore]"
To ignore case on matching or not. (default smart)
.br

.TP
.BI "-n, --nth=" "N[,..]"
Comma-separated list of field index expressions for limiting search scope.
See \fBFIELD INDEX EXPRESSION\fR for the details.
.TP
.BI "--with-nth=" "N[,..]"
Transform the presentation of each line using field index expressions
.TP
.BI "-d, --delimiter=" "STR"
Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)

.SS Search result
.TP
.B "--tac"
Reverse the order of the input

.RS
e.g. \fBhistory | sk --tac\fR
.RE
.TP
.BI "--tiebreak=" "CRI[,..]"
Comma-separated list of sort criteria to apply when the scores are tied.
.br

.br
.BR score "   Score of the fuzzy match algorithm"
.br
.BR index "   Prefers line that appeared earlier in the input stream"
.br
.BR begin "   Prefers line with matched substring closer to the beginning"
.br
.BR end "     Prefers line with matched substring closer to the end"
.br

.br
- Each criterion could be negated, e.g. (-index)
.br
- Each criterion should appear only once in the list
.SS Interface
.TP
.B "-i, --interactive"
Start the finder in the command query
.TP
.B "-c, --cmd [cmd]"
Specify the command to invoke for fetching options
.TP
.B "-I replstr"
Replace \fBreplstr\fR with the selected item
.TP
.B "-m, --multi"
Enable multi-select with tab/shift-tab
.TP
.B "--no-multi"
Disable multi-select
.TP
.BI "--bind=" "KEYBINDS"
Comma-separated list of custom key bindings. See \fBKEY BINDINGS\fR for the
details.
.TP
.B "--no-hscroll"
Disable horizontal scroll
.TP
.BI "--height=" "HEIGHT[%]"
Display sk window below the cursor with the given height instead of using
the full screen.
.TP
.BI "--min-height=" "HEIGHT"
Minimum height when \fB--height\fR is given in percent (default: 10).
Ignored when \fB--height\fR is not specified.
.TP
.BI "--layout=" "LAYOUT"
Choose the layout (default: default)

.br
.BR default "       Display from the bottom of the screen"
.br
.BR reverse "       Display from the top of the screen"
.br
.BR reverse-list "  Display from the top of the screen, prompt at the bottom"
.br

.TP
.B "--reverse"
A synonym for \fB--layout=reverse\fB

.TP
.BI "--margin=" MARGIN
Comma-separated expression for margins around the finder.
.br

.br
.RS
.BR TRBL "     Same margin for top, right, bottom, and left"
.br
.BR TB,RL "    Vertical, horizontal margin"
.br
.BR T,RL,B "   Top, horizontal, bottom margin"
.br
.BR T,R,B,L "  Top, right, bottom, left margin"
.br

.br
Each part can be given in absolute number or in percentage relative to the
terminal size with \fB%\fR suffix.
.br

.br
e.g. \fBsk --margin 10%\fR
     \fBsk --margin 1,5%\fR
.RE
.TP
.B "--inline-info"
Display finder info inline with the query
.TP
.BI "-p --prompt=" "STR"
Input prompt (default: '> ')
.TP
.BI "--cmd-prompt=" "STR"
Command prompt (default: 'c> ')
.TP
.BI "--header=" "STR"
The given string will be printed as the sticky header. The lines are displayed
in the given order from top to bottom regardless of \fB--layout\fR option, and
are not affected by \fB--with-nth\fR. ANSI color codes are processed even when
\fB--ansi\fR is not set.
.TP
.BI "--header-lines=" "N"
The first N lines of the input are treated as the sticky header. When
\fB--with-nth\fR is set, the lines are transformed just like the other
lines that follow.
.SS Display
.TP
.B "--ansi"
Enable processing of ANSI color codes
.TP
.BI "--tabstop=" SPACES
Number of spaces for a tab character (default: 8)
.TP
.BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]"
Color configuration. The name of the base color scheme is followed by custom
color mappings. Ansi color code of -1 denotes terminal default
foreground/background color. You can also specify 24-bit color in \fB#rrggbb\fR
format.

.RS
e.g. \fBsk --color=bg+:24\fR
     \fBsk --color=light,fg:232,bg:255,bg+:116,info:27\fR
.RE

.RS
.B BASE SCHEME:
    (default: dark on 256-color terminal, otherwise 16)

    \fBdark    \fRColor scheme for dark 256-color terminal
    \fBlight   \fRColor scheme for light 256-color terminal
    \fB16      \fRColor scheme for 16-color terminal
    \fBbw      \fRNo colors

.B COLOR:
    \fBfg                \fRText
    \fBbg                \fRBackground
    \fBmatched|hl        \fRText of highlighted substrings
    \fBmatched_bg        \fRBackground of highlighted substrings
    \fBcurrent|fg+       \fRText (current line)
    \fBcurrent_bg|bg+    \fRBackground (current line)
    \fBcurrent_match|hl+ \fRText of Highlighted substrings (current line)
    \fBcurrent_match_bg  \fRBackground of highlighted substrings (current line)
    \fBquery             \fRText of Query (the texts after the prompt)
    \fBquery_bg          \fRBackground of Query
    \fBinfo              \fRInfo
    \fBborder            \fRBorder of the preview window and horizontal separators (\fB--border\fR)
    \fBprompt            \fRPrompt
    \fBpointer|cursor    \fRPointer to the current line (no effect now)
    \fBmarker|selected   \fRMulti-select marker
    \fBspinner           \fRStreaming input indicator
    \fBheader            \fRHeader
.RE
.SS History
.TP
.BI "--history=" "HISTORY_FILE"
Load search history from the specified file and update the file on completion.
When enabled, \fBCTRL-N\fR and \fBCTRL-P\fR are automatically remapped to
\fBnext-history\fR and \fBprevious-history\fR.
.TP
.BI "--history-size=" "N"
Maximum number of entries in the history file (default: 1000). The file is
automatically truncated when the number of the lines exceeds the value.
.TP
.BI "--cmd-history=" "HISTORY_FILE"
Load command query history from the specified file and update the file on
completion.  When enabled, \fBCTRL-N\fR and \fBCTRL-P\fR are automatically
remapped to \fBnext-history\fR and \fBprevious-history\fR.
.TP
.BI "--cmd-history-size=" "N"
Maximum number of command query entries in the history file (default: 1000).
The file is automatically truncated when the number of the lines exceeds the
value.
.SS Preview
.TP
.BI "--preview=" "COMMAND"
Execute the given command for the current line and display the result on the
preview window. \fB{}\fR in the command is the placeholder that is replaced to
the single-quoted string of the current line. To transform the replacement
string, specify field index expressions between the braces (See \fBFIELD INDEX
EXPRESSION\fR for the details).

.RS
e.g. \fBsk --preview='head -$LINES {}'\fR
     \fBls -l | sk --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR

sk overrides \fB$LINES\fR and \fB$COLUMNS\fR so that they represent the exact
size of the preview window.

Note that you can escape a placeholder pattern by prepending a backslash.

Also, \fB{q}\fR is replaced to the current query string. \fB{cq}\fR is
replaced to the current command query string.

Preview window will be updated even when there is no match for the current
query if any of the placeholder expressions evaluates to a non-empty string.
.RE
.TP
.BI "--preview-window=" "[POSITION][:SIZE[%]][:wrap][:hidden]"
Determine the layout of the preview window. If the argument ends with
\fB:hidden\fR, the preview window will be hidden by default until
\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.
Line wrap can be enabled with \fB:wrap\fR flag.

If size is given as 0, preview window will not be visible, but sk will still
execute the command in the background.

.RS
.B POSITION: (default: right)
    \fBup
    \fBdown
    \fBleft
    \fBright
.RE

.RS
e.g. \fBsk --preview="head {}" --preview-window=up:30%\fR
     \fBsk --preview="file {}" --preview-window=down:1\fR
.RE
.SS Scripting
.TP
.BI "-q, --query=" "STR"
Start the finder with the given query
.TP
.BI "--cmd-query=" "STR"
Specify the initial query for the command query
.TP
.B "--print-query"
Print query as the first line
.TP
.BI "-f, --filter=" "STR"
Filter mode. Do not start interactive finder. It's like a fuzzy-version of
grep. skim will output the score and the item to stdout.
.TP
.BI "--expect=" "KEY[,..]"
Comma-separated list of keys that can be used to complete sk in addition to
the default enter key. When this option is set, sk will print the name of the
key pressed as the first line of its output (or as the second line if
\fB--print-query\fR is also used). The line will be empty if sk is completed
with the default enter key. If \fB--expect\fR option is specified multiple
times, sk will expect the union of the keys. \fB--no-expect\fR will clear the
list.

.RS
e.g. \fBsk --expect=ctrl-v,ctrl-t,alt-s --expect=f1,f2,~,@\fR
.RE
.TP
.B "--read0"
Read input delimited by ASCII NUL characters instead of newline characters
.TP
.B "--print0"
Print output delimited by ASCII NUL characters instead of newline characters

.TP
.B "--version"
Display version information and exit

.SH ENVIRONMENT VARIABLES
.TP
.B SKIM_DEFAULT_COMMAND
Default command to use when input is tty. On *nix systems, sk runs the command
with \fBsh -c\fR, so make sure that it's POSIX-compliant.
.TP
.B SKIM_DEFAULT_OPTIONS
Default options. e.g. \fBexport SKIM_DEFAULT_OPTIONS="--multi\fR

.SH EXIT STATUS
.BR 0 "      Normal exit"
.br
.BR 1 "      No match"
.br
.BR 2 "      Error"
.br
.BR 130 "    Interrupted with \fBCTRL-C\fR or \fBESC\fR"

.SH FIELD INDEX EXPRESSION

A field index expression can be a non-zero integer or a range expression
([BEGIN]..[END]). \fB--nth\fR and \fB--with-nth\fR take a comma-separated list
of field index expressions.

.SS Examples
.BR 1 "      The 1st field"
.br
.BR 2 "      The 2nd field"
.br
.BR -1 "     The last field"
.br
.BR -2 "     The 2nd to last field"
.br
.BR 3..5 "   From the 3rd field to the 5th field"
.br
.BR 2.. "    From the 2nd field to the last field"
.br
.BR ..-3 "   From the 1st field to the 3rd to the last field"
.br
.BR .. "     All the fields"
.br

.SH EXTENDED SEARCH MODE

Unless specified otherwise, sk will start in "extended-search mode". In this
mode, you can specify multiple patterns delimited by spaces, such as: \fB'wild
^music .mp3$ sbtrkt !rmx\fR

You can prepend a backslash to a space (\fB\\ \fR) to match a literal space
character.

.SS Exact-match (quoted)
A term that is prefixed by a single-quote character (\fB'\fR) is interpreted as
an "exact-match" (or "non-fuzzy") term. sk will search for the exact
occurrences of the string.

.SS Anchored-match
A term can be prefixed by \fB^\fR, or suffixed by \fB$\fR to become an
anchored-match term. Then sk will search for the lines that start with or end
with the given string. An anchored-match term is also an exact-match term.

.SS Negation
If a term is prefixed by \fB!\fR, sk will exclude the lines that satisfy the
term from the result. In this case, sk performs exact match by default.

.SS Exact-match by default
If you don't prefer fuzzy matching and do not wish to "quote" (prefixing with
\fB'\fR) every word, start sk with \fB-e\fR or \fB--exact\fR option. Note that
when \fB--exact\fR is set, \fB'\fR-prefix "unquotes" the term.

.SS OR operator
A single bar character term acts as an OR operator. For example, the following
query matches entries that start with \fBcore\fR and end with either \fBgo\fR,
\fBrb\fR, or \fBpy\fR.

e.g. \fB^core go$ | rb$ | py$\fR

.SH KEY BINDINGS
You can customize key bindings of sk with \fB--bind\fR option which takes
a comma-separated list of key binding expressions. Each key binding expression
follows the following format: \fBKEY:ACTION\fR

e.g. \fBsk --bind=ctrl-j:accept,ctrl-k:kill-line\fR

.B AVAILABLE KEYS:    (SYNONYMS)
    \fIctrl-[a-z]\fR
    \fIctrl-space\fR
    \fIctrl-alt-[a-z]\fR
    \fIalt-[a-zA-Z]\fR
    \fIalt-[0-9]\fR
    \fIf[1-12]\fR
    \fIenter\fR       (\fIctrl-m\fR)
    \fIspace\fR
    \fIbspace\fR      (\fIbs\fR)
    \fIalt-up\fR
    \fIalt-down\fR
    \fIalt-left\fR
    \fIalt-right\fR
    \fIalt-enter\fR   (\fIalt-ctrl-m\fR)
    \fIalt-space\fR
    \fIalt-bspace\fR  (\fIalt-bs\fR)
    \fIalt-/\fR
    \fItab\fR
    \fIbtab\fR        (\fIshift-tab\fR)
    \fIesc\fR
    \fIdel\fR
    \fIup\fR
    \fIdown\fR
    \fIleft\fR
    \fIright\fR
    \fIhome\fR
    \fIend\fR
    \fIpgup\fR        (\fIpage-up\fR)
    \fIpgdn\fR        (\fIpage-down\fR)
    \fIshift-up\fR
    \fIshift-down\fR
    \fIshift-left\fR
    \fIshift-right\fR
    \fIalt-shift-up\fR
    \fIalt-shift-down\fR
    \fIalt-shift-left\fR
    \fIalt-shift-right\fR
    or any single character

  \fBACTION:               DEFAULT BINDINGS (NOTES):
    \fBabort\fR                 \fIctrl-c  ctrl-q  esc\fR
    \fBaccept\fR                \fIenter\fR
    \fBappend-and-select\fR
    \fBbackward-char\fR         \fIctrl-b  left\fR
    \fBbackward-delete-char\fR  \fIctrl-h  bspace\fR
    \fBbackward-kill-word\fR    \fIalt-bs\fR
    \fBbackward-word\fR         \fIalt-b   shift-left\fR
    \fBbeginning-of-line\fR     \fIctrl-a  home\fR
    \fBclear-screen\fR          \fIctrl-l\fR
    \fBdelete-char\fR           \fIdel\fR
    \fBdelete-charEOF\fR        \fIctrl-d\fR
    \fBdeselect-all\fR
    \fBdown\fR                  \fIctrl-j  ctrl-n  down\fR
    \fBend-of-line\fR           \fIctrl-e  end\fR
    \fBexecute(...)\fR          (see below for the details)
    \fBexecute-silent(...)\fR   (see below for the details)
    \fBforward-char\fR          \fIctrl-f  right\fR
    \fBforward-word\fR          \fIalt-f   shift-right\fR
    \fBif-non-matched\fR
    \fBif-query-empty\fR
    \fBif-query-not-empty\fR
    \fBignore\fR
    \fBkill-line\fR
    \fBkill-word\fR             \fIalt-d\fR
    \fBnext-history\fR          (\fIctrl-n\fR on \fB--history\fR or \fB--cmd-history\fR)
    \fBpage-down\fR             \fIpgdn\fR
    \fBpage-up\fR               \fIpgup\fR
    \fBhalf-page-down\fR
    \fBhalf-page-up\fR
    \fBpreview-up\fR            \fIshift-up\fR
    \fBpreview-down\fR          \fIshift-down\fR
    \fBpreview-left\fR
    \fBpreview-right\fR
    \fBpreview-page-down\fR
    \fBpreview-page-up\fR
    \fBprevious-history\fR      (\fIctrl-p\fR on \fB--history\fR or \fB--cmd-history\fR)
    \fBselect-all\fR
    \fBtoggle\fR
    \fBtoggle-all\fR
    \fBtoggle+down\fR           \fIctrl-i  (tab)\fR
    \fBtoggle-in\fR             (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)
    \fBtoggle-out\fR            (\fB--layout=reverse*\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)
    \fBtoggle-preview\fR
    \fBtoggle-preview-wrap\fR
    \fBtoggle-sort\fR
    \fBtoggle+up\fR             \fIbtab    (shift-tab)\fR
    \fBunix-line-discard\fR     \fIctrl-u\fR
    \fBunix-word-rubout\fR      \fIctrl-w\fR
    \fBup\fR                    \fIctrl-k  ctrl-p  up\fR
    \fByank\fR                  \fIctrl-y\fR

Multiple actions can be chained using \fB+\fR separator.

    \fBsk --bind 'ctrl-a:select-all+accept'\fR

With \fBexecute(...)\fR action, you can execute arbitrary commands without
leaving sk. For example, you can turn sk into a simple file browser by
binding \fBenter\fR key to \fBless\fR command like follows.

    \fBsk --bind "enter:execute(less {})"\fR

You can use the same placeholder expressions as in \fB--preview\fR.

If the command contains parentheses, sk may fail to parse the expression. In
that case, you can use any of the following alternative notations to avoid
parse errors.

    \fBexecute[...]\fR
    \fBexecute'...'\fR
    \fBexecute"..."\fR
    \fBexecute:...\fR
.RS
This is the special form that frees you from parse errors as it does not expect
the closing character. The catch is that it should be the last one in the
comma-separated list of key-action pairs.
.RE

sk switches to the alternate screen when executing a command. However, if the
command is expected to complete quickly, and you are not interested in its
output, you might want to use \fBexecute-silent\fR instead, which silently
executes the command without the switching. Note that sk will not be
responsive until the command is complete. For asynchronous execution, start
your command as a background process (i.e. appending \fB&\fR).

With \fBif-query-empty\fR and \fBif-query-not-empty\fR action, you could
specify the action to execute depends on the query condition. For example

    \fBsk --bind 'ctrl-d:if-query-empty(abort)+delete-char'\fR

If the query is empty, skim will execute \fBabort\fR action, otherwise execute
\fBdelete-char\fR action. It is equal to `delete-char/eof`.

.SH AUTHOR
Jinzhou Zhang (\fIlotabout@gmail.com\fR)

.SH SEE ALSO
.B Project homepage:
.RS
.I https://github.com/lotabout/skim
.RE
.br

.br
.B Extra Vim plugin:
.RS
.I https://github.com/lotabout/skim.vim
.RE

.SH LICENSE
MIT
